<%-- 
    Document   : compra
    Created on : 10-may-2012, 15:09:41
    Author     : Hermanos
--%>
<%@page import="com.comprainsumos.MPersistencia.MPinsumoProveedor"%>
<%@page import="com.comprainsumos.modelo.InsumoProveedor"%>
<%@page import="java.awt.geom.Line2D"%>
<%@page import="com.comprainsumos.modelo.Carrito"%>
<%@page import="com.comprainsumos.MPersistencia.MPInsumos"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="com.comprainsumos.modelo.Insumo"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Compra</title>
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <!-- Tabla-->
        <link href="css/aristo/jquery-wijmo.css" type="text/css" rel="stylesheet"/>
        <link href="css/wijmo/jquery.wijmo-open.2.0.8.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijpager.css" rel="stylesheet" type="text/css" />
        <link href="css/wijmo/jquery.wijmo.wijgrid.css" rel="stylesheet" type="text/css" />
        <script src="js/external/jquery-1.7.1.min.js" type="text/javascript"></script>
        <script src="js/external/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>
        <script src="js/external/jquery.mousewheel.min.js" type="text/javascript"></script>
        <script src="js/external/globalize.min.js" type="text/javascript"></script>
        <script src="js/external/jquery.wijmo-open.all.2.0.8.min.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijpager.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijdatasource.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijgrid.js" type="text/javascript"></script>
        <!-- Input Numero  -->
        <link href="css/wijmo/jquery.wijmo.wijinput.css" rel="stylesheet" type="text/css" />
        <script src="js/wijmo/jquery.plugin.wijtextselection.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijinputcore.js" type="text/javascript"></script>
        <script src="js/wijmo/jquery.wijmo.wijinputnumber.js" type="text/javascript"></script>
        <%
            String ni = request.getParameter("nit");
            int nit = 0;
            if (ni != null) {
                nit = Integer.parseInt(ni);
            }
            List<InsumoProveedor> lista = new LinkedList();
            lista = MPinsumoProveedor.listarCodProv(nit);
        %>
        <script type="text/javascript">
            $(document).ready(function() {
                num =0;
                
                $("#tabla2").wijgrid({
                    selectionMode: "singleRow",
                    allowSorting: true,
                    allowPaging: true,
                    pageSize: 10,
                    data: [
            <%
                for (Iterator it = lista.iterator(); it.hasNext();) {
                    InsumoProveedor i = (InsumoProveedor) it.next();
                    out.print("['" + i.getInsumos().getNombre() + "'," + i.getInsumos().getCantidad() + "," + i.getInsumos().getStockMin() + ",'" + i.getInsumos().getUnidadmedia() + "']" + ",");
                }
            %>
                        ],
                        columns: [
                            { headerText: "Nombre" }, { headerText: "Cantidad" }, { headerText: "StockMin" }, { headerText: "Unidad" }
                        ],
                        rowStyleFormatter: function (args) {
                            if ((args.state & $.wijmo.wijgrid.renderState.rendering) && (args.type & $.wijmo.wijgrid.rowType.data)) {
                                args.$rows
                                .css("cursor", "pointer")
                                .click(function (e) {
                                    selectionChanged:  onSelectionChanged2();
                                })
                            }
                        },
                        selectionChanged: onSelectionChanged2
                    });
                    function onSelectionChanged2() {
                        if(num == 1){
                            var sc = $("#tabla2").wijgrid("selection").selectedCells();
                            var cellInfo = sc.item(0);
                            $("#nombre").html(cellInfo.value().toString())
                            $("#dialogconfirm").wijdialog("open");
                        }else
                            num = 1
                    }
                    // dialogo de agregar al carrito
                    $("#dialogconfirm").wijdialog({
                        autoOpen: false,
                        height: 180,
                        width: 400,
                        modal: true,
                        buttons: { Aceptar: function () {
                           
                            },
                            Cerrar: function () {
                                $(this).wijdialog("close");
                            }
                        },
                        captionButtons: {
                            pin: { visible: false },
                            refresh: { visible: false },
                            toggle: { visible: false },
                            minimize: { visible: false },
                            maximize: { visible: false }
                        }
                    });
                    //input de numero
                    $("#textbox1").wijinputnumber(
                    {
                        type: 'numeric',
                        minValue: 0,
                        maxValue: 999999999,
                        decimalPlaces: 0,
                        showSpinner: true
                    });
                    //carrito de compra
                    $(".mainCompose").hide();
                    $('.loader').hide();
                    $('#errortxt').hide();

                    $('.compose').click(function() {
                        $('.mainCompose').slideToggle();
                    });
    
                    $('.sendbtn').click(function(e) {
                        e.preventDefault();
                        $('.sendbtn').hide();
                        $('.loader').show();
    	
                        if($('#mymsg').val() == "") {
                            $('#errortxt').show();
                            $('.sendbtn').show();
                            $('.loader').hide();
                        }
                        else {
                            $('sendbtn').hide();
                            $('.loader').show();
                            $('#errortxt').hide();
    		
                            var formQueryString = $('#sendprivatemsg').serialize(); // form data for ajax input
                            finalSend();    		
                        }
    
                        // possibly include Ajax calls here to external PHP
                        function finalSend() {
                            $('.mainCompose').delay(1000).slideToggle('slow', function() {
                                $('#composeicon').addClass('sent').removeClass('compose').hide();
    		
                                // hide original link and display confirmation icon
                                $('#composebtn').append('<img src="imagenes/check-sent.png" />');
                            });
                        }
                    });
            

                });
        </script>
        <style>
            .break { display: block; height: 20px; }

            /* @group core */
            #wrap { display: block; padding-top: 5px; width: 50%; margin: 0 auto;}

            #right { width: 350px; float: left; display: block; }

            /* @group modal form */
            input[type="text"], input[type="password"], textarea, select { outline: none; }

            #msgform { width: 330px; background: #faf7e3; border: 8px solid #f0ecd0; -moz-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px; padding: 4px 14px; top: -1px; z-index: 9; }

            .mainCompose { display: inline; }

            .msgInput { border: 1px solid #d8d5bb; border-top-color: #b1ae99; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; width: 290px; font-size: 15px; color: #727167; padding: 4px 7px; font-family: Arial, Tahoma, sans-serif; }
            .msgField { border: 1px solid #d8d5bb; border-top-color: #b1ae99; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; width: 290px; color: #a4a39c; color: #727167; font-size: 15px; padding: 5px 9px; font-family: Arial, Tahoma, sans-serif; height: 140px; margin-bottom: 20px; }

            #composebtn img { cursor: pointer; }

            .tofield { margin-bottom: 2px; padding: 3px 7px;}

            .containmsg { margin-left: 50px; display: block; float: right; position: relative; }
            .containmsg .mainCompose { position: absolute; left: -33px; top: 32px; }

            .recipient { display: block; padding: 3px 7px; text-decoration: none; font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; background: #eae7d1; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; color: #949286; border: 1px solid #d8d5bb; }
            .recipient:hover { color: #75746a; border: 1px solid #93928d; }

            .userslist { display: inline; list-style: none; padding: 0; margin-bottom: 5px; position: relative; top: 10px; margin-left: 2px; }


            #tofield:focus, #mymsg:focus { box-shadow: 0px 0px 7px #007eff; }

            #msgform label { display: inline; color: #827f6a; font-size: 14px; font-weight: bold; font-family: "Trebuchet MS", Arial, sans-serif; margin-bottom: 4px; }

            .calloutUp { height: 0; width: 0; border-bottom: 12px solid #f0ecd0; border-left: 12px dotted transparent; border-right: 12px dotted transparent; left: 0px; top: 0px; margin-left: 30px; z-index: 10; }
            .calloutUp2 { position: relative; left: -12px; top: 8px; border-bottom: 12px solid #faf7e3; border-left: 12px dotted transparent; border-right: 12px solid transparent; z-index: 11; }

            p#errortxt { margin-top: -15px; font-size: 0.7em; font-style: italic; color: #555; margin-bottom: 10px; }

            .sendbtn { display: inline-block; outline: none; margin-bottom: 12px; cursor: pointer; font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 12px; color: #827f6a; padding: 7px 12px; border: 1px solid #cac8bb; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; border-top-color: #dddac3; text-shadow: 0px 0px 1px rgba(97,97,93,.3); -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.2); -moz-box-shadow: 0 1px 2px rgba(0,0,0,.2); background: #f6f5ea; background: -webkit-gradient(linear, left top, left bottom, from(#f9f9f3), to(#f5f4e6)); background: -moz-linear-gradient(top,  #f9f9f3,  #f5f4e6); filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#f9f9f3', endColorstr='#f5f4e6'); }

            .sendbtn:hover { background: #fff; background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#fbfbf5)); background: -moz-linear-gradient(top,  #fff,  #fbfbf5); filter:  progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff', endColorstr='#fbfbf5'); color: #93928d; }

            /* @group clearfix */
            .vemergente:after { content: "."; display: block; clear: both; visibility: hidden; line-height: 0; height: 0; }
            .vemergente { display: inline-block; }

            html[xmlns] .vemergente { display: block; }
            * html .vemergente { height: 1%; }
        </style>
    </head>
    <body>

        <div id="wrap">
            <div class="vemergente">
                <section id="right">
                    <!-- Inicio de ventana emergente -->
                    <div class="containmsg">
                        <%
                            List<Carrito> listaCarrito = (List<Carrito>) session.getAttribute("carrito");
                            if (listaCarrito == null) {
                                listaCarrito = new LinkedList<Carrito>();
                            }
                        %>
                        <p id="composebtn"><img src="imagenes/compose.gif" alt="compose" class="compose" id="composeicon" />(<%=listaCarrito.size()%>)</p>

                        <div class="mainCompose">
                            <div class="calloutUp">
                                <div class="calloutUp2">.
                                </div>
                            </div>	
                            <div id="msgform">
                                <form name="sendprivatemsg" id="sendprivatemsg" action="controladores/registroCotizacion.jsp" method="post">

                                    <label for="tofield" class="tofield">Insumos</label>
                                    <ul class="userslist vemergente">
                                        <li>...</li>
                                    </ul>
                                    <ul class="userslist">
                                        <%

                                            for (Iterator<Carrito> it = listaCarrito.iterator(); it.hasNext();) {
                                                Carrito c = it.next();

                                        %>
                                        <li><a href="Insumos.jsp" class="recipient"><%=c.getProductoP().getInsumos().getNombre()%></br><%=c.getCantidad()%><%=c.getProductoP().getInsumos().getUnidadmedia()%>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;&nbsp;<%=c.getProductoP().getProvedores().getNombre()%></a></li>
                                        <% }
                                            if (listaCarrito.size() == 0) {
                                                out.println("<li>No hay Productos Para cotizar</li>");
                                            }
                                        %> 
                                    </ul>
                                    <div class="break"></div>

                                    <p id="errortxt">**Ingrese Algo!</p>

                                    <div id="sendbtncontain"><a class="sendbtn">Cotizar</a><img src="imagenes/ajax-loader.gif" class="loader" /></div>
                                    <input type="submit" value="Cotizar"/>
                                </form>
                            </div>
                        </div>
                    </div>
                    <!-- @Final de la ventana -->
                </section>
            </div>
        </div>
        <div style="width: 30%;">

            <table rules="all" id="tabla2">
            </table>
        </div>
        <div id="dialogconfirm" title="Agregar al Carrito">
            <p>
                <label>Nombre:</label><label id="nombre"></label></br>
            </p>
            <form>
                <label>Cantidad:</label>
                <input style="width: 100%" type="text" id="textbox1" value="1231230" />
            </form>
        </div>                       

    </body>
</html>
